#include "guibutton.h"
#include "../maindrawscene.h"

GuiButton::GuiButton()
    : GuiBaseNode(),
      mSelected(false)
{
    // 初始按钮颜色
    this->initBtnColor();
}

GuiButton::GuiButton(int id,wxString nodename)
    : GuiBaseNode(id,nodename),
      mSelected(false)
{
    // 初始按钮颜色
    this->initBtnColor();
}

GuiButton::~GuiButton()
{

}

/// 初始按钮颜色
void GuiButton::initBtnColor(void)
{
    this->setColor(wxColour(128, 128, 128,200),
                   wxColour(245, 245, 245,200),
                   wxColour(165, 42, 42,200));
    this->setBorderColor(wxColour(255,255,255,255));

    mShowColour = this->getNormalColor();
}

/// 设置结点显示颜色
void GuiButton::setColor(wxColour normalcol,wxColour overcol,wxColour clickcol)
{
    GuiBaseNode::setColor(normalcol,overcol,clickcol);

    mShowColour = this->getNormalColor();
}

/// 工作区域改变
void GuiButton::changeWorkingRect(wxRect workingrect)
{

}

/// 更新
void GuiButton::update(void)
{

}

/// 绘制
void GuiButton::draw(maindrawscene *painter)
{
    painter->DrawRectangle(this->getRect(),
                           wxColour(0,0,0,255),
                           0.0f,
                           wxRealPoint(0.0f,0.0f),
                           1.0f,1.0f,
                           true,
                           mShowColour,
                           2.0f);
    painter->DrawText2(this->getNodeName().ToUTF8().data(),
                       wxRect(this->getRect().GetX(),this->getRect().GetY()+2,this->getRect().GetWidth(),this->getRect().GetHeight()),
                       1.0f,
                       mShowColour);
}

/// 处理鼠标事件
bool GuiButton::OnMMouseEvent(wxMouseEvent event)
{
    if(event.Moving() && mSelected == false)
    {
        if(this->getRect().Contains(event.GetX(),event.GetY()))
            mShowColour = this->getOverColor();
        else
            mShowColour = this->getNormalColor();
    }
    else if(event.LeftDown() && this->getRect().Contains(event.GetX(),event.GetY()) && mSelected == false)
    {
        mShowColour = this->getClickColor();
        mSelected = true;

        return true;
    }

    return false;
}

/// 重置结点状态
void GuiButton::reset(void)
{

}
